function DMACarousel(){
	var divContent,divWrapper,divSlider;
	var items = [];
	var divItems = [];
	var render_n_items;
	var that = this;
	var width = 100;
	var height = 125;

	var exp = /[^a-zA-Z]*/;
	var actorSelector = new ActorSelector(window.actors);


	this.addItem = function(item){
		items.push(item);
	}

	this.updateSlider = function(id,value){
		actorSelector.select(id,value);
	}

	this.createSlider = function(content,fn_click_callback){
		items = actorSelector.queryActors();
		divItems = {};

		divContent = content;
		if(divContent.children.length>=3){
			divContent.removeChild(divContent.children[2]);
		}
		divWrapper = document.createElement("div");
		divSlider = document.createElement("div");

		divWrapper.setAttribute("class","dma-wrapper");
		divSlider.setAttribute("class","dma-slider");		

		for(var i=0;i<items.length;i++){
			var item = items[i];
			var divItem = document.createElement("div");
			var imgItem = document.createElement("img");

			imgItem.setAttribute("src",item.image);
			imgItem.setAttribute("class","dma-item-img");
			divItem.setAttribute("class","dma-item");
			divItem.setAttribute("style","width:" + width + "px;height:" + height +"px;");
			imgItem.setAttribute("actorId",item.id);
			imgItem.addEventListener("click",fn_click_callback);

			divItem.appendChild(imgItem);
			divSlider.appendChild(divItem);
			divItems[item.id] = divItem;
		}

		divWrapper.appendChild(divSlider);
		divContent.appendChild(divWrapper);

		return divContent;
	}

	this.selectActor = function(actor){
		divItems[actor.id].style.opacity = "0.4";
		divItems[actor.id].style.filter = "alpha(opacity=40)";
	}

	this.reselectActors = function(){
		for(i=0;i<items.length;i++){
			divSlider.children[items[i].id-1].style.opacity = "1";
			divSlider.children[items[i].id-1].style.filter = "alpha(opacity=100)";	
		}
	}

	this.render = function(){
		divSlider.style.marginLeft = "0px";
		$("#next-carousel").mouseover(function(){
			that.animate(0);
		});

		$("#prev-carousel").mouseover(function(){
			that.animate(1);
		});	

		$("#next-carousel").mouseout(function(){
			$(".dma-slider").stop();
		});	

		$("#prev-carousel").mouseout(function(){
			$(".dma-slider").stop();
		});	

		render_n_items =  $(".dma-item").size();	
	}


	this.animate = function(type){
		if(type==0){
			animate_right();
		}else{
			animate_left();
		}			
	}

	var animate_right = function(){
		var ml = -(getMarginLeft(divSlider));

		if(ml < ( (render_n_items-2)*width ) ) {
			$(".dma-slider").animate({"margin-left":"-=" + 40},100,"swing",animate_right);	
		}
		
	};

	var animate_left = function(){
		var that = this;
		var ml = getMarginLeft(divSlider);

		if(ml < 0) {
			$(".dma-slider").animate({"margin-left":"+=" + 40},100,"swing",animate_left);		
		}				
	}

	var getWidth = function(e){
		var r = exp.exec(e.style.width);
		if(r.length>0){
			return parseInt(r[0]);
		}
		return null;
	};

	var getMarginLeft = function(e){
		var r = exp.exec($(".dma-slider")[0].style.marginLeft);
		if(r.length>0){
			return parseInt(r[0]);
		}
		return null;
	}
}
